//
//  MyViewController.m
//  TaurusXi
//
//  Created by xicheng on 15/11/27.
//  Copyright © 2015年 xicheng. All rights reserved.
//

#import "MyViewController.h"
#import "RegisterViewController.h"
#import "LoginViewController.h"
#import "PhoneNumbCertificationViewController.h"
#import "UserHelper.h"

@interface MyViewController ()

@property(nonatomic,strong)UILabel *incomeLabel;

@property(nonatomic,strong)NSMutableArray *buttonArray;

@property(nonatomic,strong)NSMutableArray *topButtonArray;


@property(nonatomic,strong) UIButton *topButton;
@property(nonatomic,strong) UIButton *leftTopButton;
@property(nonatomic,strong) UIButton *leftBottomButton;
@property(nonatomic,strong) UIButton *bottomButton;
@property(nonatomic,strong) UIButton *rightTopButton;
@property(nonatomic,strong) UIButton *rightBottomButton;

@property(nonatomic,strong) UILabel *descLabel;
//@property(nonatomic,strong) UILabel *moneyLabel;
@property(nonatomic,strong) UIButton *seeDetailButton;
@property(nonatomic,strong) UIButton *startMakeMoneyButton;
@property(nonatomic,assign)Boolean isTheFirstPageFlag;

//@property(nonatomic,strong)NSDictionary *indexDic;

@property(nonatomic,assign)NSInteger firstIndex;
@property(nonatomic,assign)NSInteger secondIndex;

@property(nonatomic,strong)NSDictionary *resultDIC;

@end

@implementation MyViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  [self initView];
  [self loadData];
}


-(void)loadData{
  
  self.isTheFirstPageFlag = YES;
  
  self.firstIndex = 0;
  self.secondIndex = 0;
  
  Boolean isLoginFlag = [[UserHelper shareUserInstance] isLogin];
  if (!isLoginFlag) {
    return;
  }
  
  [self showSimplePro];
  @weakify(self);
  [[Api shareApiInstance]getStarDataWithResponce:^(id object) {
    @strongify(self);
    [self hideSimpleProWithDelay:0];
   
    if ([object isKindOfClass:[NSDictionary class]]) {
      self.resultDIC = [object objectForKey:@"data"];
      [self setDataWithIndex:self.firstIndex AndFirstPageFlag:self.isTheFirstPageFlag];
    }
    
    
  } AndError:^(id object, NSError *error) {
    @strongify(self);
    [self hideSimpleProWithDelay:0];
  }];
  
}


- (void)initView {
  self.navigationController.navigationBarHidden = YES;
  self.customNavigationBar.hidden = YES;
  self.view.clipsToBounds= YES;
  //  self.view.backgroundColor = [UIColor blueColor];
  
  [self initBgAndTitle];
  [self initTitleForButton];
  [self initSixButton];
  [self initFinger];
  
//  [self initTitleButton];
  
  // Do any additional setup after loading the view.
}

-(void)initFinger{
  UIButton *fingerBt = [[UIButton alloc]init];
  [fingerBt setImage:ImageWithContentsOfFileWithPng(@"ic_space_fingerprint_click@2x") forState:UIControlStateHighlighted];
  [fingerBt setImage:ImageWithContentsOfFileWithPng(@"ic_space_fingerprint@2x") forState:UIControlStateNormal];
  [fingerBt sizeToFit];
  [fingerBt addTarget:self action:@selector(changeFinger) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:fingerBt];
  fingerBt.center = CGPointMake(self.deviceWidth-60, self.deviceHeight-110);
  
}


-(void)changeFinger{

  self.isTheFirstPageFlag = !self.isTheFirstPageFlag;
  
  [self showFirstPage:self.isTheFirstPageFlag];
  
  NSInteger selectedIndex = self.isTheFirstPageFlag?self.firstIndex:self.secondIndex;
  
  [self setSwitchDataWithIndex:selectedIndex];
}


-(void)setSwitchDataWithIndex:(NSInteger)index{
  
  if (self.isTheFirstPageFlag) {
    self.firstIndex = index;
  }else{
    self.secondIndex = index;
  }
  
  [self setDataWithIndex:index AndFirstPageFlag:self.isTheFirstPageFlag];
}


-(void)setDataWithIndex:(NSInteger)selectedIndex AndFirstPageFlag:(Boolean) flag{

  [self setButtonList:self.buttonArray WithIndex:selectedIndex];
  
  
  CGPoint descPoint = self.descLabel.center;
  
  CGPoint incomePoint = self.incomeLabel.center;
  
  
  if (flag) {
  
    switch (selectedIndex) {
      case 0:
        
        self.startMakeMoneyButton.hidden = NO;
        self.descLabel.text = @"今日收益";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"todayIncome"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        break;
      case 1:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"累计收益";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"totalIncome"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        break;
        
      case 2:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"可投资金额";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"usemoney"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        break;
        
      case 5:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"应还金额";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"totalOutcome"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        break;
        
      
        
      case 3:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"总资产";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"total"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        
        break;
        
      case 4:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"可提现金额";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"useTXMoney"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        
        
        break;
        
      default:
        break;
    }
    
    
  }else{
    
    switch (selectedIndex) {
      case 0:
        
        self.startMakeMoneyButton.hidden = NO;
        self.descLabel.text = @"我的债权";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"tenderCount"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        break;
      case 1:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"星券管理";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"couponCount"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        break;
        
      case 2:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"银行卡管理";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"bankCount"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        break;
        
//      case 5:
//        
//        self.startMakeMoneyButton.hidden = YES;
//        self.descLabel.text = @"其他";
//        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"totalOutcome"]];
//        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
//        
//        break;
//        
        
        
      case 3:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"邀请好友";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"inviteUserCount"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        
        break;
        
      case 4:
        
        self.startMakeMoneyButton.hidden = YES;
        self.descLabel.text = @"站内信";
        self.incomeLabel.text = [NSString stringWithFormat:@"%@",[self.resultDIC objectForKey:@"noticeCounts"]];
        [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
        
        
        
        break;
        
      default:
        break;
    }
    
    
    
  
  }


  [self.descLabel sizeToFit];
  [self.incomeLabel sizeToFit];
  
  self.descLabel.center = descPoint;
  self.incomeLabel.center = incomePoint;
  
  
}

-(void)showFirstPage:(Boolean) flag{
  
    [self setButtonWithTarget:self.topButton AndTitle:flag?@"今日收益":@"我的债权" AndImageNormal:@"ic_space_coin_icon1_@2x"];
     [self setButtonWithTarget:self.leftTopButton AndTitle:flag?@"累计收益":@"星券管理" AndImageNormal:@"ic_space_coin_icon1_@2x"];
     [self setButtonWithTarget:self.leftBottomButton AndTitle:flag?@"可投金额":@"银行卡管理" AndImageNormal:@"ic_space_coin_icon1_@2x"];
     [self setButtonWithTarget:self.bottomButton AndTitle:flag?@"应还金额":@"其他" AndImageNormal:@"ic_space_coin_icon1_@2x"];
     [self setButtonWithTarget:self.rightTopButton AndTitle:flag?@"总资产":@"邀请好友" AndImageNormal:@"ic_space_coin_icon1_@2x"];
     [self setButtonWithTarget:self.rightBottomButton AndTitle:flag?@"可提现金额":@"站内信" AndImageNormal:@"ic_space_coin_icon1_@2x"];
  
}



-(void)initBgAndTitle{
  
  UIImageView *bgImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, kStatusBarHeight,self.view.frame.size.width,self.deviceHeight-kStatusBarHeight -kTabBarHeight)];
  bgImageView.image = ImageWithContentsOfFileWithPng(@"bg_beijing_@2x");
  bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  self.customNavigationBar.hidden = YES;
  [self.view addSubview:bgImageView];
  
  const CGFloat kTitleHeight = 44;
  
  UIImageView *imageTitleButtom = [[UIImageView alloc]initWithFrame:CGRectMake(0, kStatusBarHeight+kTitleHeight+10, self.deviceWidth, 106/2)];
  imageTitleButtom.image =ImageWithContentsOfFileWithPng(@"bg_title_bottom@2x");
  [self.view addSubview:imageTitleButtom];
  
  UIImageView *imageTitleLeft = [[UIImageView alloc]initWithFrame:CGRectMake(0, kStatusBarHeight+kTitleHeight, 314/2, 125/2)];
  imageTitleLeft.image =ImageWithContentsOfFileWithPng(@"bg_title_left@2x");
  [self.view addSubview:imageTitleLeft];
   //
  
  UIImageView *progressBg = [[UIImageView alloc]initWithFrame:CGRectZero];
  progressBg.backgroundColor = [UIColor grayColor];
  progressBg.image = ImageWithContentsOfFileWithPng(@"bg_jindutiao@2x");
  [progressBg sizeToFit];
  
  UIView *progressView = [[UIView alloc]initWithFrame:CGRectMake(6, imageTitleLeft.frame.origin.y+imageTitleLeft.frame.size.height+10, progressBg.frame.size.width, progressBg.frame.size.height)];
  [progressView setClipsToBounds:YES];
  progressView.backgroundColor = [UIColor clearColor];
  [self.view addSubview:progressView];
  [progressView addSubview:progressBg];
  
  UIImageView *progressImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
  UIImage *progressImage = ImageWithContentsOfFileWithPng(@"bg_hongtiao@2x");
  progressImage = [progressImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6) resizingMode:UIImageResizingModeStretch];
  progressImageView.image = progressImage;
  [progressView addSubview:progressImageView];
  CGFloat progress = 0.6;
  progressImageView.frame = CGRectMake(1, 2, (progressView.frame.size.width-2)*progress, progressView.frame.size.height-2);
  
  UILabel *progressLabel = [[UILabel alloc ]init];
  progressLabel.text = @"布卡:60/100";
  progressLabel.textColor = [UIColor whiteColor];
  progressLabel.font = [UIFont systemFontOfSize:10];
  [progressLabel sizeToFit];
  [progressView addSubview:progressLabel];
  progressLabel.center =CGPointMake(progressView.frame.size.width/2, progressView.frame.size.height/2);
  
  
  //
  UIImageView *avatarImageView = [[UIImageView alloc]initWithFrame:CGRectMake(25, 25+kTitleHeight, 25,25)];
  avatarImageView.image = ImageWithContentsOfFileWithPng(@"ic_space_title_photo@2x");
  [self.view addSubview:avatarImageView];
  
  
  //
  UIImageView *phoneImageView = [[UIImageView alloc]initWithFrame:CGRectMake(5, 50+kTitleHeight, 138,29)];
  phoneImageView.image = ImageWithContentsOfFileWithPng(@"bg_space_title_name");
  [self.view addSubview:phoneImageView];
  
  
  UILabel *avatarLabel = [[UILabel alloc] init];
  avatarLabel.text = @"布卡";
  avatarLabel.textColor = [UIColor whiteColor];
  avatarLabel.font = [UIFont systemFontOfSize:10];
  [avatarLabel sizeToFit];
  avatarLabel.frame = CGRectMake(54, 36+kTitleHeight, avatarLabel.frame.size.width, avatarLabel.frame.size.height);
  [self.view addSubview:avatarLabel];
  
  //
  UILabel *phoneLabel = [[UILabel alloc] init];
  phoneLabel.text = @"18513175348";
  phoneLabel.textColor = [UIColor whiteColor];
  phoneLabel.font = [UIFont systemFontOfSize:12];
  [phoneLabel sizeToFit];
  phoneLabel.frame = CGRectMake(25, 56+kTitleHeight, phoneLabel.frame.size.width, phoneLabel.frame.size.height);
  [self.view addSubview:phoneLabel];
  
  
  UIView *navigationBar = [[UIView alloc]initWithFrame:CGRectMake(0, kStatusBarHeight, self.deviceWidth, kTitleHeight)];
  navigationBar.backgroundColor = [UIColor colorWithRed:3/255. green:22/255. blue:52/255. alpha:0.77];
  
  [self.view addSubview:navigationBar];
  
  UILabel *titleLable =[[UILabel alloc]init];
  titleLable.text = @"金牛座";
  titleLable.textColor = [UIColor whiteColor];
  titleLable.font = [UIFont systemFontOfSize:18];
  [titleLable sizeToFit];
  [navigationBar addSubview:titleLable];
  titleLable.center = CGPointMake(self.deviceWidth/2, navigationBar.frame.size.height/2);

  
}


- (void)initTitleButton {

  UIImageView *leftImageView =
      [[UIImageView alloc] initWithFrame:CGRectMake(17, 31, 30, 30)];
  leftImageView.image =ImageWithContentsOfFileWithPng(@"ic_space_cion@2x");
  [self.view addSubview:leftImageView];
  
  UIImageView *rightImageView = [[UIImageView alloc]
      initWithFrame:CGRectMake(self.deviceWidth - 17 - 30, 31, 30, 30)];
  rightImageView.image =ImageWithContentsOfFileWithPng(@"ic_space_sign@2x");
  
  [self.view addSubview:rightImageView];
}

- (void)initTitleForButton {
 
  self.topButtonArray = [[NSMutableArray alloc]init];
  UIButton *one =
      [[UIButton alloc] initWithFrame:CGRectMake(155, 90-50+44, 30, 30)];
  [self initButton:one AndImage:@"ic_space_title_phone@2x" AndImageHighlighted:@"ic_space_title_phone_click@2x"];
  [one addTarget:self action:@selector(oneClick) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:one];
  [self.topButtonArray addObject:one];
  one.selected = YES;
  
  UIButton *two = [[UIButton alloc]
      initWithFrame:CGRectMake(one.frame.origin.x + 44, one.frame.origin.y, 30,
                               30)];
  [self initButton:two AndImage:@"ic_space_title_safe@2x" AndImageHighlighted:@"ic_space_title_safe_click@2x"];
  [two addTarget:self action:@selector(twoClick) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:two];
  [self.topButtonArray addObject:two];
  
  
  UIButton *three = [[UIButton alloc]
      initWithFrame:CGRectMake(two.frame.origin.x + 44, two.frame.origin.y, 30,
                               30)];
  [self initButton:three AndImage:@"ic_space_title_id@2x" AndImageHighlighted:@"ic_space_title_id_click@2x"];
  [three addTarget:self action:@selector(threeClick) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:three];
  [self.topButtonArray addObject:three];
  
  UIButton *four = [[UIButton alloc]
      initWithFrame:CGRectMake(three.frame.origin.x + 44, three.frame.origin.y,
                               30, 30)];
   [self initButton:four AndImage:@"ic_space_title_email@2x" AndImageHighlighted:@"ic_space_title_email_click@2x"];
  [four addTarget:self action:@selector(fourClick) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:four];
  [self.topButtonArray addObject:four];
}


-(void)oneClick{
  [self setButtonList:self.topButtonArray WithIndex:0];
}

-(void)twoClick{
  [self setButtonList:self.topButtonArray WithIndex:1];
}

-(void)threeClick{
  [self setButtonList:self.topButtonArray WithIndex:2];
}

-(void)fourClick{
  [self setButtonList:self.topButtonArray WithIndex:3];
}




-(void)initButton:(UIButton *)target AndImage:(NSString *)imageFile AndImageHighlighted:(NSString *)imageHighlightedFile{
  UIImage *highlightedImage = ImageWithContentsOfFileWithPng(imageHighlightedFile);
  [target setImage:highlightedImage forState:UIControlStateSelected];
  [target setImage:highlightedImage forState:UIControlStateHighlighted];
  [target setImage:ImageWithContentsOfFileWithPng(imageFile) forState:UIControlStateNormal];
  target.clipsToBounds = YES;

}

- (void)initSixButton {

  self.buttonArray = [[NSMutableArray alloc]init];
  
  UIImageView *centerImageBg = [[UIImageView alloc]initWithImage:ImageWithContentsOfFileWithPng(@"bg_xingyu_yuan@2x")];
  
  [centerImageBg sizeToFit];
  [self.view addSubview:centerImageBg];
  
  centerImageBg.center = CGPointMake(self.view.center.x, self.view.center.y + 69 / 2);
  
  UIView *uiView =
      [[UIView alloc] initWithFrame:CGRectMake(0, 0, 684 / 2, 756 / 2)];
      
  [self.view addSubview:uiView];
  uiView.center = CGPointMake(self.view.center.x, self.view.center.y + 69 / 2);
  
  //
  {
  self.topButton =
      [[UIButton alloc] initWithFrame:CGRectMake(228 / 2, 0, 229 / 2, 90)];
 
    [self initButton:self.topButton WidthTitle:@"今日收益" AndImageNormal:@"ic_space_coin_icon1_@2x" AndBackgroundNormal:@"ic_space_angle_1@2x" AndBackgroundHighlight:@"ic_space_angle_1_click@2x"];
  CGFloat _top = 25;
  self.topButton.imageEdgeInsets = UIEdgeInsetsMake(_top, (self.topButton.frame.size.width-self.topButton.imageView.frame.size.width)/2, self.topButton.frame.size.height-self.topButton.imageView.frame.size.height-_top, (self.topButton.frame.size.width-self.topButton.imageView.frame.size.width)/2);
  
  CGFloat _titleTop = _top+30;
   self.topButton.titleEdgeInsets = UIEdgeInsetsMake(_titleTop, -44,0,0);
  
  [self.topButton addTarget:self action:@selector(clickTop:) forControlEvents:UIControlEventTouchUpInside];
  
  [uiView addSubview:self.topButton];
    [self.buttonArray addObject:self.topButton];
    self.topButton.selected = YES;
  }
  //
  {
  self.leftTopButton =
      [[UIButton alloc] initWithFrame:CGRectMake(0, 178 / 2, 229 / 2, 100)];
  
     [self initButton:self.leftTopButton WidthTitle:@"累计收益" AndImageNormal:@"ic_space_coin_icon1_@2x" AndBackgroundNormal:@"ic_space_angle_2@2x" AndBackgroundHighlight:@"ic_space_angle_2-_click@2x"];

  CGFloat _leftTop = 35;
  self.leftTopButton.imageEdgeInsets = UIEdgeInsetsMake(_leftTop, (self.leftTopButton.frame.size.width-self.leftTopButton.imageView.frame.size.width)/2, self.leftTopButton.frame.size.height-self.leftTopButton.imageView.frame.size.height-_leftTop, (self.leftTopButton.frame.size.width-self.leftTopButton.imageView.frame.size.width)/2);
  
  CGFloat _leftTopTitle = _leftTop-95;
  self.leftTopButton.titleEdgeInsets = UIEdgeInsetsMake(_leftTopTitle, -35,0,10);
  
  [self.leftTopButton addTarget:self action:@selector(clickLeftTop:) forControlEvents:UIControlEventTouchUpInside];
  [uiView addSubview:self.leftTopButton];
  [self.buttonArray addObject:self.leftTopButton];
  }
  
  {
  self.leftBottomButton =
      [[UIButton alloc] initWithFrame:CGRectMake(1, 378 / 2, 229 / 2, 100)];
    
     [self initButton:self.leftBottomButton WidthTitle:@"可投金额" AndImageNormal:@"ic_space_coin_icon1_@2x" AndBackgroundNormal:@"ic_space_angle_3@2x" AndBackgroundHighlight:@"ic_space_angle_3_click@2x"];
    CGFloat _leftBottomTop = 30;
    self.leftBottomButton.imageEdgeInsets = UIEdgeInsetsMake(_leftBottomTop, (self.leftBottomButton.frame.size.width-self.leftBottomButton.imageView.frame.size.width)/2, self.leftBottomButton.frame.size.height-self.leftBottomButton.imageView.frame.size.height-_leftBottomTop, (self.leftBottomButton.frame.size.width-self.leftBottomButton.imageView.frame.size.width)/2);
    
    CGFloat _leftTopTitle = _leftBottomTop+25;
    self.leftBottomButton.titleEdgeInsets = UIEdgeInsetsMake(_leftTopTitle, -35,0,10);
    
    [self.leftBottomButton addTarget:self action:@selector(clickLeftBottom:) forControlEvents:UIControlEventTouchUpInside];
    
  [uiView addSubview:self.leftBottomButton];
   [self.buttonArray addObject:self.leftBottomButton];
  }
  
  {
  self.rightTopButton = [[UIButton alloc]
      initWithFrame:CGRectMake(uiView.frame.size.width - 229 / 2, 178 / 2,
                               229 / 2, 100)];
     [self initButton:self.rightTopButton WidthTitle:@"总资产" AndImageNormal:@"ic_space_coin_icon1_@2x" AndBackgroundNormal:@"ic_space_angle_4@2x" AndBackgroundHighlight:@"ic_space_angle_4_click@2x"];
    
    CGFloat _rightTop = 35;
    self.rightTopButton.imageEdgeInsets = UIEdgeInsetsMake(_rightTop, (self.rightTopButton.frame.size.width-self.rightTopButton.imageView.frame.size.width)/2, self.rightTopButton.frame.size.height-self.rightTopButton.imageView.frame.size.height-_rightTop, (self.rightTopButton.frame.size.width-self.rightTopButton.imageView.frame.size.width)/2);
    
  CGFloat _rightTopTitle = _rightTop-95;
  self.rightTopButton.titleEdgeInsets = UIEdgeInsetsMake(_rightTopTitle, -35,0,10);
    
  [self.rightTopButton addTarget:self action:@selector(clickRightTop:) forControlEvents:UIControlEventTouchUpInside];
  [uiView addSubview:self.rightTopButton];
     [self.buttonArray addObject:self.rightTopButton];
  }
    
  
  {
  self.rightBottomButton = [[UIButton alloc]
      initWithFrame:CGRectMake(uiView.frame.size.width - 229 / 2, 378 / 2,
                               229 / 2, 100)];
  
     [self initButton:self.rightBottomButton WidthTitle:@"可提现金额" AndImageNormal:@"ic_space_coin_icon1_@2x" AndBackgroundNormal:@"ic_space_angle_5@2x" AndBackgroundHighlight:@"ic_space_angle_5_click@2x"];
      CGFloat _rightBottomTop = 30;
    self.rightBottomButton.imageEdgeInsets = UIEdgeInsetsMake(_rightBottomTop, (self.rightBottomButton.frame.size.width-self.rightBottomButton.imageView.frame.size.width)/2, self.rightBottomButton.frame.size.height-self.rightBottomButton.imageView.frame.size.height-_rightBottomTop, (self.rightBottomButton.frame.size.width-self.rightBottomButton.imageView.frame.size.width)/2);
    
    CGFloat _rightBottomTitle = _rightBottomTop+25;
    self.rightBottomButton.titleEdgeInsets = UIEdgeInsetsMake(_rightBottomTitle, -35,0,10);
    
    [self.rightBottomButton addTarget:self action:@selector(clickRightBottom:) forControlEvents:UIControlEventTouchUpInside];
    
  [uiView addSubview:self.rightBottomButton];
    [self.buttonArray addObject:self.rightBottomButton];
  }
    
  
  {
  self.bottomButton = [[UIButton alloc]
      initWithFrame:CGRectMake(228 / 2, uiView.frame.size.height - 90, 229 / 2,
                               90)];
    [self initButton:self.bottomButton WidthTitle:@"应还金额" AndImageNormal:@"ic_space_coin_icon1_@2x" AndBackgroundNormal:@"ic_space_angle_4_@2x" AndBackgroundHighlight:@"ic_space_angle_4_click@2x"];
    CGFloat _bottom = 30;
    self.bottomButton.imageEdgeInsets = UIEdgeInsetsMake(_bottom, (self.bottomButton.frame.size.width-self.bottomButton.imageView.frame.size.width)/2, self.bottomButton.frame.size.height-self.bottomButton.imageView.frame.size.height-_bottom, (self.bottomButton.frame.size.width-self.bottomButton.imageView.frame.size.width)/2);
    
    CGFloat _bottomTitle = _bottom-80;
    self.bottomButton.titleEdgeInsets = UIEdgeInsetsMake(_bottomTitle, -35,0,10);
    
    [self.bottomButton addTarget:self action:@selector(clickBottom:) forControlEvents:UIControlEventTouchUpInside];
  [uiView addSubview:self.bottomButton];
    [self.buttonArray addObject:self.bottomButton];
  }
  
  
  UIImageView *middleView =
      [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 230, 199)];
      
  middleView.image = ImageWithContentsOfFileWithPng(@"ic_space_middle_bg@2x");
                                           
  [uiView addSubview:middleView];
  middleView.center = CGPointMake(172, 189);
  
  //
  
  self.descLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  self.descLabel.text = @"今日收益";
  self.descLabel.font = [UIFont systemFontOfSize:14];
  self.descLabel.textColor = RGB(255,254,179);
  [self.descLabel sizeToFit];
  [uiView addSubview:self.descLabel];
  self.descLabel.center = CGPointMake(uiView.frame.size.width/2,135+4);
  
  self.incomeLabel = [[UILabel alloc]initWithFrame:CGRectZero];
  self.incomeLabel.text = [NSString stringWithFormat:@"%@元",@"20000"];
  self.incomeLabel.textColor = RGB(225,176,45);
  self.incomeLabel.font = [UIFont systemFontOfSize:22];
  [self.incomeLabel sizeToFit];
  [uiView addSubview:self.incomeLabel];
  self.incomeLabel.center =CGPointMake(uiView.frame.size.width/2,self.descLabel.center.y+25);
  
  self.seeDetailButton = [[UIButton alloc]init];
  [self.seeDetailButton setTitleColor:RGB(255,254,179) forState:UIControlStateNormal];
  [self.seeDetailButton setTitle:@"查看详情" forState:UIControlStateNormal];
  [self.seeDetailButton addTarget:self action:@selector(seeDetail:) forControlEvents:UIControlEventTouchUpInside];
  [self.seeDetailButton sizeToFit];
  self.seeDetailButton.titleLabel.font= [UIFont systemFontOfSize:12];
  [uiView addSubview:self.seeDetailButton];
  self.seeDetailButton.center =CGPointMake(uiView.frame.size.width/2,self.incomeLabel.center.y+40);
  
  self.startMakeMoneyButton = [[UIButton alloc]init];
  [self.startMakeMoneyButton setImage:ImageWithContentsOfFileWithPng(@"bt_taurus-recommendation_bg_normal_click@2x") forState:UIControlStateHighlighted];
  [self.startMakeMoneyButton setImage:ImageWithContentsOfFileWithPng(@"bt_taurus-recommendation_bg_normal@2x") forState:UIControlStateNormal];
  [self.startMakeMoneyButton sizeToFit];
  [self.startMakeMoneyButton addTarget:self action:@selector(improveButtonClick:) forControlEvents:UIControlEventTouchUpInside];
  [uiView addSubview:self.startMakeMoneyButton];
  self.startMakeMoneyButton.center =CGPointMake(uiView.frame.size.width/2,self.seeDetailButton.center.y+40);
}

-(void)initButton:(UIButton *)target WidthTitle:(NSString *)title AndImageNormal:(NSString *)imageName AndBackgroundNormal:(NSString *)backgroundImageName AndBackgroundHighlight:(NSString *)hightLightBackgroundImageName {
  
  [target setBackgroundImage:ImageWithContentsOfFileWithPng(backgroundImageName) forState:UIControlStateNormal];
  UIImage *highlightImage = ImageWithContentsOfFileWithPng(hightLightBackgroundImageName);
  
  [target setBackgroundImage:highlightImage forState:UIControlStateHighlighted];
  [target setBackgroundImage:highlightImage forState:UIControlStateSelected];
  
  UIImage *image = ImageWithContentsOfFileWithPng(imageName);
  [target setImage:image forState:UIControlStateNormal];
  [target setImage:image forState:UIControlStateHighlighted];
  
  target.titleLabel.font = [UIFont systemFontOfSize:14];
  [target setTitle:title forState:UIControlStateNormal];
  
  [target setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
  [target setTitleColor:[UIColor blackColor] forState:UIControlStateSelected];
  [target setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  [target.titleLabel sizeToFit];
  target.titleLabel.userInteractionEnabled = NO;
  target.imageView.userInteractionEnabled = NO;


}

-(void)setButtonWithTarget:(UIButton *)target AndTitle:(NSString *)title AndImageNormal:(NSString *)imageNormal{
  [target setTitle:title forState:UIControlStateNormal];
  UIImage *image = ImageWithContentsOfFileWithPng(imageNormal);
  [target setImage:image forState:UIControlStateNormal];
  [target setImage:image forState:UIControlStateHighlighted];
}


- (void)goToRegister:(UIButton *)sender {
  PhoneNumbCertificationViewController *registerViewController =
      [[PhoneNumbCertificationViewController alloc]
          initWithNibName:@"PhoneNumbCertificationViewController"
                   bundle:nil];
  [self.navigationController pushViewController:registerViewController
                                       animated:YES];
  self.tabBarController.tabBar.hidden = YES;
}

- (void)goToLogin:(UIButton *)sender {
  LoginViewController *loginViewController =
      [[LoginViewController alloc] initWithNibName:@"LoginViewController"
                                            bundle:nil];
  [self.navigationController pushViewController:loginViewController
                                       animated:YES];
  self.tabBarController.tabBar.hidden = YES;
}




-(void)clickTop:(UIButton *)sender{
  
  if (self.topButton.isSelected) {
    return;
  }
  [self setSwitchDataWithIndex:0];
  
  [self setButtonList:self.buttonArray WithIndex:0];
 
}
-(void)clickLeftTop:(UIButton *)sender{
  if (self.leftTopButton.isSelected) {
    return;
  }
  [self setSwitchDataWithIndex:1];
  
[self setButtonList:self.buttonArray WithIndex:1];
}
-(void)clickLeftBottom:(UIButton *)sender{
  
  if (self.leftBottomButton.isSelected) {
    return;
  }
  [self setSwitchDataWithIndex:2];
  
  [self setButtonList:self.buttonArray WithIndex:2];
}

-(void)clickRightTop:(UIButton *)sender{
  
  if (self.rightTopButton.isSelected) {
    return;
  }
  [self setSwitchDataWithIndex:3];
  
  [self setButtonList:self.buttonArray WithIndex:3];
}
-(void)clickRightBottom:(UIButton *)sender{
  
  
  if (self.rightBottomButton.isSelected) {
    return;
  }
  [self setSwitchDataWithIndex:4];
  
  
  [self setButtonList:self.buttonArray WithIndex:4];
}
-(void)clickBottom:(UIButton *)sender{
  
  
  if (self.bottomButton.isSelected) {
    return;
  }
  [self setSwitchDataWithIndex:5];
  
  
  [self setButtonList:self.buttonArray WithIndex:5];
}

-(void)seeDetail:(UIButton *)sender{
  
}

-(void)setButtonList:(NSArray *)arraty WithIndex:(NSInteger)index{
  for (NSInteger i= 0; i<arraty.count; i++) {
    UIButton *indexButton = [arraty objectAtIndex:i];
    if (index == i) {
      indexButton.selected  = YES;
      NSLog(@"___index:%ld",(long)index);
    }else{
      indexButton.selected = NO;
    }
  }
}

-(void)improveButtonClick:(UIButton *)sender{
  
}



- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}

- (void)viewWillDisappear:(BOOL)animated {
  //  [super viewDidAppear:animated];
  self.tabBarController.tabBarController.tabBar.hidden = NO;
}

- (void)viewWillAppear:(BOOL)animated {
  //  [super viewDidAppear:animated];
  self.tabBarController.tabBarController.tabBar.hidden = NO;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little
preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
